package com.ktjy.service.impl;

import com.ktjy.entity.Flower;
import com.ktjy.mapper.FlowerMapper;
import com.ktjy.service.FlowerService;
import com.ktjy.service.FlowerService;
import com.ktjy.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("flowerService")
public class FlowerServiceImpl implements FlowerService {
    @Autowired
    FlowerMapper flowerMapper;

    @Override
    public Page<Flower> findPage(Flower flower, Integer pageNo, Integer pageSize) {
        Page<Flower> page=new Page<>();
        //设置当前的页码数
        page.setPageNo(pageNo);
        //设置每页的条数
        page.setPageSize(pageSize);
        //设置总记录数
        Integer count=flowerMapper.count(flower);
        page.setTotalCount(count);
        //设置每页的数据
        List<Flower> list = flowerMapper.getPage(flower, page.offset(), page.getPageSize());
        page.setData(list);

        return page;
    }

    @Override
    @Transactional
    public boolean save(Flower flower) {
        return flowerMapper.insert(flower)>0;
    }

    @Override
    public Flower findById(Long id) {
        return flowerMapper.getById(id);
    }

    @Override
    public boolean update(Flower flower) {
        return flowerMapper.update(flower)>0;
    }

    @Override
    public boolean delete(Long id) {
        return flowerMapper.delete(id)>0;
    }

    @Override
    public Flower findByName(String name) {
        return flowerMapper.getByName(name);
    }
}
